home *** CD-ROM | disk | FTP | other *** search
- /* a HyperCard XFCN that lets you delete some files from the disk
- * ... by giving the user the std files dialog
- * repeatedly ....
- *
- * call it as HyperTalk function: delFiles (x0, y0)
- *
- * where x0, y0 are the screen coordinates to base the dialog boxes
- * on ... 0,0 works for a Mac Plus....
- *
- * Don't bother with any error checking ... just do it!
- *
- * make it XFCN number 2232 and name it "delFiles"
- *
- * 871229 ^z
- */
-
-
- #include <MacTypes.h>
- #include <OSUtil.h>
- #include <FileMgr.h>
- #include <StdFilePkg.h>
- #include <WindowMgr.h>
- #include <HyperXCmd.h>
-
- pascal void main (XCmdBlockPtr paramPtr);
- int GetFileZ (Str255 *fn, int *vRef, int x0, int y0);
- void pStrCopy (char *p1, char *p2);
- long atol (char *s);
-
- pascal void main (paramPtr)
- XCmdBlockPtr paramPtr;
- {
- WindowRecord w_record;
- WindowPtr info_window;
- Rect b_rect;
- Str255 fn0;
- int vRef0, x0, y0;
-
- if (paramPtr->paramCount != 2)
- {
- SysBeep (10);
- return;
- }
- x0 = atol (*(paramPtr->params[0]));
- y0 = atol (*(paramPtr->params[1]));
-
- b_rect.top = 30 + y0;
- b_rect.left = 12 + x0;
- b_rect.bottom = 52 + y0;
- b_rect.right = 500 + x0;
- info_window = NewWindow (&w_record, &b_rect, "\p", (Boolean)1, dBoxProc,
- (WindowPtr)-1, (Boolean)0, (long)0);
- ShowWindow (info_window);
- SetPort (info_window);
- TextFont (0);
- b_rect.top = 0;
- b_rect.left = 0;
- b_rect.bottom = 22;
- b_rect.right = 488;
-
- EraseRect (&b_rect);
- MoveTo ( 4,15);
- DrawString ("\pSelect file(s) to (irreversibly!) delete ... choose 'Cancel' when done.");
-
- while (GetFileZ (&fn0, &vRef0, x0, y0))
- FSDelete (fn0, vRef0);
-
- CloseWindow (info_window);
- return;
- }
-
-
- /* following variables and routine do the standard files dialog
- * to get the name of the file to use ... cribbed from the MiniEdit
- * example that comes with LSC.... put the dialog box someplace
- * reasonable, nothing complex ....
- */
-
- int GetFileZ (fnp, vRefp, x0, y0)
- Str255 *fnp;
- int *vRefp, x0, y0;
- {
- SFTypeList myTypes;
- Point SFGwhere;
- SFReply reply;
-
- SFGwhere.v = 90 + y0;
- SFGwhere.h = 82 + x0;
-
- SFGetFile( SFGwhere, "\p", 0L, -1, myTypes, 0L, &reply);
-
- if (reply.good)
- {
- pStrCopy( (char *)reply.fName, (char *)fnp);
- *vRefp = reply.vRefNum;
- return (1);
- }
- else return (0);
- }
-
-
- /* routine to copy a pascal string from one place to another.... used in
- * above Standard Files routine.... from LSC library....
- */
-
- void pStrCopy (p1, p2 )
- register char *p1, *p2;
- {
- register int len;
-
- len = *p2++ = *p1++;
- while (--len >= 0)
- *p2++ = *p1++;
- return;
- }
-
-
- /* function to convert alphabetic string to a long integer ... from LSC
- * library.... simplified to avoid using isspace() & isdigit() ....
- */
-
- long atol (s)
- register char *s;
- {
- register char signflag = 0;
- register long r = 0;
-
- while ((*s == ' '))
- s++;
-
- if (*s == '-')
- {
- signflag = 1;
- s++;
- }
- else if (*s == '+')
- s++;
-
- while (*s >= '0' && *s <= '9')
- r = r * 10 + (*s++ - '0');
-
- return (signflag ? -r : r);
- }
-
-
-
-
-